<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件对象</title>
    <style>
        #areaDiv {
            border: 1px solid black;
            width: 300px;
            height: 50px;
            margin-bottom: 10px;
        }
        #showMsg {
            border: 1px solid black;
            width: 300px;
            height: 30px;
        }
    </style>
</head>


<script type="text/javascript">
    window.onload = function() {
        var areaDiv = document.getElementById("areaDiv");
        var showMsg = document.getElementById("showMsg");
        
        areaDiv.onmousemove = function(event) {
            // 在showMsg中显示鼠标的坐标
            var x = event.clientX;
            var y = event.clientY;
            
            // if(!event) {
            //     event = window.event;
            // }

            // 解决事件对象的兼容性
            event = event || window.event;

            showMsg.innerHTML = "x = " + x + ", y = " + y;    
            
        }
    }
</script>
<body>
    <div id="areaDiv">

    </div>
    <div id="showMsg">

    </div>
</body>
</html>